<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <div th:replace="./widget/base"></div>
</head>
<body>

<div id="operationLogToolbar">
    <a th:if="${#authorization.expression('hasRole('''+ SYSTEM_ADMIN +''') OR hasAuthority(''/COMPONENT/SYSTEM/OPERATION_LOG/PAGE_ALL/OPERATION_LOG_DELETE_ALL'')')}" href="javascript:" class="easyui-linkbutton" iconCls="fa fa-close" plain="true"
       onclick="operationLogDeleteAll();">删除</a>

    <a th:if="${#authorization.expression('hasRole('''+ SYSTEM_ADMIN +''') OR hasAuthority(''/COMPONENT/SYSTEM/OPERATION_LOG/PAGE_ALL/OPERATION_LOG_CLEAR_ALL'')')}" href="javascript:" class="easyui-linkbutton" iconCls="fa fa-close" plain="true"
       onclick="operationLogClearAll();">清空日志</a>

</div>
<table id="operationLog"></table>

<script type="text/javascript">
    $(function () {

        var OPERATION_TYPE = [];
        expressui.ajax({
            url: Url.System.Api.DICTIONARY + '/list_all_by_key/OPERATION_TYPE',
            async: false,
            success: function (data) {
                if (data) {
                    OPERATION_TYPE = data;
                }
            }
        });

        var columns = [
            {field: 'checkbox', checkbox: true},
            {field: 'id', title: 'ID'},
            {field: 'userName', title: '访问用户'},
            {field: 'ipAddress', title: '用户 IP'},
            {
                field: 'operationType', title: '操作类型', formatter: function (value, row, index) {
                    return expressui.grid.formatter(value, OPERATION_TYPE);
                }
            },
            {field: 'operation', title: '操作说明'},
            {field: 'requestTime', title: '请求耗时（毫秒）'},
            {field: 'requestUrl', title: '请求地址'},
            {field: 'requestMethod', title: '请求方法'},
            {field: 'requestParameter', title: '请求参数'},
            {field: 'acceptLanguage', title: '请求语言'},
            {field: 'referer', title: '请求来源'},
            {field: 'userAgent', title: '用户代理'},
            {field: 'handler', title: 'Handler'},
            {field: 'sessionId', title: 'Session ID'},
            {field: 'cookie', title: 'Cookie'},
            {field: 'contentType', title: '响应文本类型'},
            {field: 'status', title: '响应状态码'},
            {field: 'gmtCreated', title: '创建时间'}
            ];
        $('#operationLog').datagrid(expressui.grid.create, {
            title: '操作日志',
            columns: [columns],
            url: Url.System.Api.OPERATION_LOG + '/page_all'
        });
    });

    function operationLogDeleteAll() {
        $('#operationLog').datagrid(expressui.grid.postCheckedLessOneOrShowAlert, {
            url: Url.System.Api.OPERATION_LOG + '/delete_all',
            method: 'post',
            success: '删除成功',
            reload: {type: 'datagrid', selector: '#operationLog'}
        });
    }

    function operationLogClearAll() {
        $.messager.confirm('信息', '确定要操作吗', function (ok) {
            if(ok) {
                $.ajax({url: Url.System.Api.OPERATION_LOG + '/clear_all', type:'POST', dataType:'JSON',success:function (data) {
                        $.messager.show({title: '信息', msg: '操作成功'});
                        $('#operationLog').datagrid('reload');
                    }, error:function (xhr) {
                        if(xhr.status !== 200) {
                            $.messager.alert('信息', '操作失败：' + xhr.responseJSON.message, 'error');
                        } else {
                            $.messager.show({title: '信息', msg: '操作成功'});
                            $('#operationLog').datagrid('reload');
                        }
                    }})
            }
        });

    }

</script>

</body>
</html>